﻿@model  Himall.Model.CollocationDataModel
<link rel="stylesheet" type="text/css" href="~/Content/bootstrap-datetimepicker.min.css">
<script type="text/javascript" src="~/Scripts/bootstrap-datetimepicker.js"></script>
<script type="text/javascript" src="~/Scripts/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript">
    $(function () {
        $("#Title").focus();
     //   $(".start_datetime").val('@DateTime.Now.ToString("yyyy-MM-dd")');
        var Now = '@DateTime.Now.ToString("yyyy-MM-dd")';
        $(".start_datetime").datetimepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose: true,
            weekStart: 1,
            minView: 2
        });
        $(".end_datetime").datetimepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose: true,
            weekStart: 1,
            minView: 2
        });
        $('.end_datetime').datetimepicker('setEndDate', "@ViewBag.EndTime");
        $('.end_datetime').datetimepicker('setStartDate', $(".start_datetime").val());
        $('.start_datetime').datetimepicker('setStartDate', Now);
        $('.start_datetime').datetimepicker('setEndDate', "@ViewBag.EndTime");
        //$(".start_datetime").click(function () {
        //    $('.end_datetime').datetimepicker('show');
        //});
        //$(".end_datetime").click(function () {
        //    $('.start_datetime').datetimepicker('show');
        //});

        $('.start_datetime').on('changeDate', function () {
            if ($(".end_datetime").val()) { 
                if ($(".start_datetime").val() > $(".end_datetime").val()) {
                    $('.end_datetime').val($(".start_datetime").val());
                }
            }

            $('.end_datetime').datetimepicker('setStartDate', $(".start_datetime").val());
            //alert($(".start_datetime").val());
        });
        $('.end_datetime').on('changeDate', function () {
            $('.start_datetime').datetimepicker('setEndDate', $(".end_datetime").val());
        });


    });
</script>
<style>
table input[type="text"]{ border:1px solid #ddd; width:64px; padding:0 5px; height:24px; line-height:24px; margin:1px; border-radius:2px;}
table input[readonly]{border: 0;background-color: transparent;}
table p{ line-height:26px;}
table th,table td{ text-align:center;}
</style>
<div class="container">
    <ul class="nav nav-tabs-custom clearfix">
        <strong>组合购</strong>
        <li><a href="@Url.Action("Management")">活动管理</a></li>
        <li class="active"><a>编辑组合购</a></li>
        <li class=""><a href="@Url.Action("buyService")">购买服务</a></li>
        <em class="primary-btn">
            <span class="glyphicon glyphicon-question-sign"></span>
            <div class="primary">
                <h3>温馨提示：</h3>
                <span>*</span><p>显示店铺已经申请的组合购活动列表</p>
            </div>
        </em>
    </ul>
    @using (Html.BeginForm("AddLimitItem", "Collocation", FormMethod.Post, new { id = "form1" }))
    {<input type="hidden" id="collocationId"  value="@Model.Id"/>
        <div class="form-horizontal">
            <div class="form-group">
                <label class="col-sm-2 control-label" for=""><b style="color:red;">*</b>活动标题：</label>
                <div class="col-sm-3">@Html.EditorFor(item => item.Title, new { htmlAttributes = new { @class = "form-control input-sm" } }) </div>
                <div class="col-sm-5"><span class="help-default">活动标题是商家对组合购活动的别名.</span></div>
            </div>
            <div class="form-group">
                @{var mainPro = Model.CollocationPoruducts.Where(a => a.IsMain == true).FirstOrDefault();}
                @*<label class="col-sm-2 control-label" for=""><b style="color:red;">*</b>主商品：</label>
                    <div class="col-sm-3"><a class="btn btn-primary btn-sm" id="SelectProduct"><span class="glyphicon glyphicon-plus-sign"></span>&nbsp; 选择主商品</a></div>*@
                <input type="hidden" id="MainProductId" name="MainProductId" value="@mainPro.ProductId" />
            </div>
            <div class="form-group">
                <div class="col-sm-9 col-sm-offset-2" id="mainProducts">
                    <table id="MainTable" class="table table-bordered">
                        <thead>
                            <tr>
                                <th>主商品</th>
                                <th>规格</th>
                                <th>原价格/组合价格</th>
                            </tr>
                        </thead>
                        <tbody>

                            <tr>
                                <td>
                                    <a href="/product/detail/@mainPro.ProductId" target="_blank" title="@mainPro.ProductName">
                                        <img src="@mainPro.ImagePath/1_50.png">
                                    </a>
                                </td>
                                <td>
                                    @foreach (var sku in mainPro.CollocationSkus)
                                {
                                        <p>@sku.SKUName</p>
                                }
                                </td>
                                <td>
                                    @foreach (var sku in mainPro.CollocationSkus)
                                	{

                                        <p class="skutd" data-pid="@mainPro.ProductId" data-skuid="@sku.SkuID">
                                            <input type="text" value="@sku.SkuPirce" readonly="">
                                            <input type="text" value="@sku.Price">
                                        </p>
                                	}
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label" for=""><b style="color:red;">*</b>搭配商品：</label>
                <div class="col-sm-3"><a class="btn btn-primary btn-sm" id="SelectOtherProducts"><span class="glyphicon glyphicon-plus-sign"></span>&nbsp; 添加搭配商品</a></div>
                <input type="hidden" id="OtherProductIds" name="OtherProductIds" value="" />
            </div>
            <div class="form-group">
                <div class="col-sm-9 col-sm-offset-2" id="otherProducts">

                    <table id="OtherTable" class="table table-bordered">
                        <thead><tr><th>搭配商品</th><th>规格</th><th>原价格/组合价格</th><th>排序</th><th>操作</th></tr></thead>
                        <tbody>
                            @{var pros = Model.CollocationPoruducts.Where(a => a.IsMain == false);}
                            @foreach (var t in pros)
                        {
                                <tr class="otherTR" data-pid="@t.ProductId">
                                    <td><a href="/product/detail/@t.ProductId" target="_blank" title="@t.ProductName"><img src="@t.ImagePath/1_50.png"></a></td>

                                    <td>
                                        @foreach (var sku in t.CollocationSkus)
                                    {
                                            <p>@sku.SKUName</p>
                                    }
                                    </td>
                                    <td>
                                        @foreach (var sku in t.CollocationSkus)
                                    {

                                            <p class="skutd" data-pid="@t.ProductId" data-skuid="@sku.SkuID">
                                                <input type="text" value="@sku.SkuPirce" readonly="">
                                                <input type="text" value="@sku.Price">
                                            </p>
                                    }
                                    </td>
                                    <td class="swaptd"><span class="glyphicon glyphicon-circle-arrow-up"></span> <span class="glyphicon glyphicon-circle-arrow-down"></span></td>
                                    <td><span class='btn-a'><a onclick="Remove(this,@t.ProductId)">删除</a></span></td>
                                </tr>
                        }
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label" for=""><b style="color:red;">*</b>开始时间：</label>
                <div class="col-sm-3">
                    <input type="text" data-d-group="0" value="@Model.StartTime.ToString("yyyy-MM-dd")" name="StartTime" class="auto form-control input-sm start_datetime" id="StartTime">
                </div>
                <div class="col-sm-5"><span class="help-default">开始时间必填.</span></div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label" for=""><b style="color:red;">*</b>结束时间：</label>
                <div class="col-sm-3">
                    <input type="text" data-d-group="0" value="@Model.EndTime.ToString("yyyy-MM-dd")" name="EndTime" class="auto form-control input-sm end_datetime" id="EndTime">
                </div>
                <div class="col-sm-5"><span class="help-default">结束时间必须晚于开始时间.</span></div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label" for=""><b style="color:red;"></b>组合描述:</label>
                <div class="col-sm-10">@Html.TextAreaFor(item => item.ShortDesc, 4, 50, new { @class = "form-control input-sm" })</div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="button" class="btn btn-primary" onclick="EditCollocation()">保存</button><label class="label-inline" for=""><a href="@Url.Action("Management")">返回</a></label>
                </div>
            </div>
        </div>
    }
</div>
<script src="~/Scripts/jquery.himallLinkage.nocreate.js"></script>
<script src="~/Scripts/jquery.hiMallDatagrid.js"></script>
<script src="~/Scripts/jquery.ColloproductSelector.js"></script>
<script type="text/javascript">
    var otherIds = [];
    $(function () {
        //$("#MainProductId").val(selectedProducts[0].id);
        // CreateMainSkuTable(selectedProducts);
        $(".otherTR").each(function(index,item) { otherIds.push($(item).data("pid")) });
        $("#OtherTable tbody tr").first().find('.glyphicon-circle-arrow-up').addClass('disabled');
        $("#OtherTable tbody tr").last().find('.glyphicon-circle-arrow-down').addClass('disabled');
        $("#SelectOtherProducts").click(function () {
            $.productSelector.show(otherIds, function (selectedProducts) {
                CreateOtherSkuTable(selectedProducts)
            }, 'selleradmin', true);
        });
    });
</script>
<script src="~/Areas/SellerAdmin/Scripts/Collocation.js"></script>